package com.aat.dxfy.buddy.test01;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.implementation.FixedValue;
import net.bytebuddy.matcher.ElementMatchers;

public class Test01 {

	public void test() throws InstantiationException, IllegalAccessException {
		Class<?> dynamicType = new ByteBuddy().subclass(Object.class).method(ElementMatchers.named("toString"))
				.intercept(FixedValue.value("Hello World!")).make().load(getClass().getClassLoader()).getLoaded();
		assertThat(dynamicType.newInstance().toString(), is("Hello World!"));
	}

	private void assertThat(String string, Object object) {
		System.out.println("1: "+string);
		System.out.println("2: "+object);
	}

	private Object is(String string) {
		return string;
	}

	public static void main(String[] args) {
		Test01 t=new Test01();
		try {
			t.test();
		} catch (InstantiationException | IllegalAccessException e) {
			e.printStackTrace();
		}
	}

}
